package com.wutong.eams.controller;

import com.wutong.eams.enums.RequestMethod;
import com.wutong.eams.enums.Role;
import com.wutong.eams.other.Router;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
@WebServlet("/transit/*")
public class TransitController extends BaseController {
    @Override
    public Role getPermission() {
        return Role.USER;
    }

    @Override
    public boolean needPermission() {
        return false;
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        new StudentManagerController().routerHandle();
        super.init(config);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        getRouter().transit(req, resp, RequestMethod.GET, CONTENT_TYPE_TEXT_HTML);
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPut(req, resp);
        getRouter().transit(req, resp, RequestMethod.PUT, CONTENT_TYPE_TEXT_HTML);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
        getRouter().transit(req, resp, RequestMethod.POST, CONTENT_TYPE_TEXT_HTML);
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doDelete(req, resp);
        getRouter().transit(req, resp, RequestMethod.DELETE, CONTENT_TYPE_TEXT_HTML);
    }
}
